﻿using System;
using System.Windows;
using System.Windows.Media;
using _3DTicTacToe.Core;

namespace _3DTicTacToe
{
    internal partial class PlayerPropertiesWindow : Window
    {
        public Player Player { get; private set; }

        public PlayerPropertiesWindow()
        {
            InitializeComponent();

            var list = new BrushList();
            playerColorCBox.DataContext = list;
            continueButton.IsEnabled = false;
            playerNameTBox.IsValidNameChanged += playerNameTBox_IsValidNameChanged;

            playerColorCBox.SelectedIndex = new Random().Next(0, list.Count - 1);
        }

        void playerNameTBox_IsValidNameChanged(bool valid)
        {
            continueButton.IsEnabled = valid;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Player = new Player(playerNameTBox.Text,
                                (Color) new ColorConverter().ConvertFrom(playerColorCBox.SelectedValue));
            Close();
        }
    }
}
